import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { viteMockServe } from 'vite-plugin-mock';
import Markdown from 'unplugin-vue-markdown/vite';
import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer';
import federation from '@originjs/vite-plugin-federation';
import pkg from './package.json';

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  console.log(command, mode);

  return {
    server: {
      port: 8890,
      proxy: {
        '/image': 'http://10.122.4.77:9000'
      }
    },
    esbuild: {
      supported: { decorators: true }
    },
    css: {
      postcss: {
        plugins: [tailwindcss, autoprefixer]
      }
    },
    plugins: [
      vue({
        include: [/\.vue$/, /\.md$/]
      }),
      federation({
        name: 'app-design',
        remotes: {
          'app-instance': 'http://localhost:8889/assets/remoteEntry.js'
        },
        shared: ['vue']
      }),
      Markdown({
        headEnabled: true
      }),
      // mock服务
      viteMockServe({
        enable: true,
        logger: true,
        mockPath: './mock/controller/'
      })
    ],
    build: {
      minify: false,
      assetsDir: '@xc/app-design',
      target: 'esnext',
      sourcemap: true,
      emptyOutDir: true,
      rollupOptions: {
        output: {
          dir: './dist',
          assetFileNames: '@xc/app-design/[ext]/[name]-[hash].[ext]',
          chunkFileNames: '@xc/app-design/js/[name]-[hash].js',
          entryFileNames: '@xc/app-design/js/[name]-[hash].js'
        }
      }
    }
  };
});
